package com.nowcoder.code.hjnc;

import java.util.Stack;

public class NC52 {


    public boolean isValid(String s) {
        if (s.length() % 2 != 0) {
            return false;
        }
        char[] cs = s.toCharArray();

        Stack<Character> stack = new Stack<>();
        for (char c : cs) {
            if (c == ')' || c == ']' || c == '}') {
                if (stack.isEmpty() || stack.pop() != c) {
                    return false;
                }
            } else {
                if (c == '[') {
                    stack.push(']');
                } else if (c == '(') {
                    stack.push(')');
                } else {
                    stack.push('}');
                }
            }

        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        System.out.println(new NC52().isValid("[]"));
    }


}
